﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    @*  查询条件 *@
    <form class="layui-form layui-row layui-col-space16" lay-filter="ID-table-demo-search">
        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="rolesName" id="rolesName" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-btn-container layui-col-xs12">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
        </div>
        <a onclick="location.href='/Users/GetAddRoles'" class="layui-btn layui-icon layui-icon-add-1" style="float:right">新增角色</a>
    </form>
    <hr />
    <table class="layui-hide" id="ID-table-demo-search"></table>
    <script>
         layui.use('table',function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            Seach();
            // 搜索提交
            form.on('submit(demo-table-search)', function(data){
              var field = data.field; // 获得表单字段
              var rolesName=$("#rolesName").val()
              // 执行搜索重载
              table.reload('ID-table-demo-search', {
                page: {
                  curr: 1 // 重新从第 1 页开始
                },
                where: {
                    rolesName:rolesName
                } // 搜索的字段
              });
              layer.msg('搜索成功');
              console.log(field)
              Seach();
              return false; // 阻止默认 form 跳转
            });
               
            
            // 搜索提交
            function Seach() {
                console.log(rolesName)
                $.ajax({
                    type: 'get',
                    url: '@ViewBag.RBACWrite'+"/api/Roles/SearchRoles",
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [[
                                {field:'rolesId', width:150, title: '序号', sort: true},
                                {field:'rolesCode', width:150, title: '角色编码'},
                                {field:'rolesName', width:150, title: '角色名称'},
                                {field:'createdTime', width:150, title: '创建时间',templet: '<div>{{ layui.util.toDateString(d.createdTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                {field:'createdOwner', title: '创建人', minWidth: 150},
                                {field:'isStatus', width:150, title: '状态', templet: function(d){
                                    if(d.isStatus ==1){
                                        return '<span style="color: blue">有效</span>';
                                    }
                                    else {
                                        return '<span style="color: gray">无效</span>';
                                    }
                                }},//操作列
                                {
                                fixed: 'right', width: 300, title: '操作', align:'center', templet: function (d)
                                {
                                    return '<a class="layui-btn layui-btn-xs layui-icon layui-icon-edit" lay-on="test-page-custom" onclick="UpdRoles(' + d.rolesId + ')">编辑</a><button class="layui-btn layui-btn-xs layui-icon layui-icon-delete"  lay - event="moredel" onclick="DelRoles(' + d.rolesId + ')">删除</a > '
                                },
                            }
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
        });
    </script>

</body>
</html>


